package Statement;

import util.DbUtil;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @author Jason
 * @PACKAGE_NAME AddDeleteCheckAndCorrect
 * @Description 删除数据
 * @date 2023-12-06 14:01
 */
public class DeleteTest {
     public static int delete(Integer id) throws SQLException, ClassNotFoundException {
        String sql = "delete from sys where id="+id;
        DbUtil dbUtil = new DbUtil();
        Connection conn = dbUtil.getConnection();
        Statement statement = conn.createStatement();
        int execute = statement.executeUpdate(sql);
        System.out.println("操作了"+execute+"条数据");
        /*关闭数据库*/
        dbUtil.closeStatement(statement);
        dbUtil.closeConnection(conn);
        return execute;
    }

    public static void main(String[] args) {
        try {
            int delete = DeleteTest.delete(145);
            if(delete != 0){
                System.out.println("删除成功");
            }
            else{
                System.out.println("删除失败");
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
